package cn.woochen.mvvmframe.activity

import android.view.View
import androidx.work.OneTimeWorkRequestBuilder
import androidx.work.WorkManager
import cn.woochen.comlib.util.OnSingleClickListener
import cn.woochen.comlib.util.ext.setOnSingleClickListener
import cn.woochen.mvvmframe.R
import cn.woochen.mvvmframe.config.BaseActivity
import cn.woochen.mvvmframe.databinding.ActivityWorkManagerBinding
import cn.woochen.mvvmframe.viewmodels.EmptyViewModel
import cn.woochen.mvvmframe.worker.UploadLogWorker
import java.util.concurrent.TimeUnit

/**
 * 工作管理
 *@author chenwuchao
 *@time 2023-4-7 9:06
 */
class WorkManagerActivity : BaseActivity<ActivityWorkManagerBinding, EmptyViewModel>(), OnSingleClickListener {

    override fun setContentView(): Int = R.layout.activity_work_manager

    override fun initData() {
        mBinding.tvTest.setOnSingleClickListener(this)
    }

    override fun onSingleClick(v: View?) {
        when (v) {
            mBinding.tvTest -> {
                val workRequest = OneTimeWorkRequestBuilder<UploadLogWorker>()
                    .setInitialDelay(1, TimeUnit.MINUTES)
                    .build()
                val enqueue = WorkManager.getInstance(mContext).enqueue(workRequest)
            }
        }
    }
}